import 'package:fate_blind_box/network/Api.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';

import 'state.dart';

class MemberAddLogic extends GetxController {
  final MemberAddState state = MemberAddState();

  @override
  void onReady() {
    // TODO: implement onReady
    super.onReady();
    if(Get.arguments!=null){
      state.matchmakerId = Get.arguments;
    }
  }

  addMember() async {
    if(state.textEditingController.text.isEmpty){
      EasyLoading.showToast('请输入姓名');
      return;
    }
    EasyLoading.show();
    Api.getInstance().addMember(
      matchmakerId: state.matchmakerId,
      name: state.textEditingController.text,
    ).then((value){
      EasyLoading.dismiss();
      if(value){
        EasyLoading.showToast("添加成功");
        Get.back();
      }
    });
  }


  @override
  void onClose() {
    // TODO: implement onClose
    super.onClose();
    state.textEditingController.dispose();
  }
}
